/*    */ package com.qmsk.business.captcha;
/*    */ 
/*    */ import java.io.OutputStream;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ import javax.servlet.http.HttpServletResponse;
/*    */ import javax.servlet.http.HttpSession;
/*    */ import org.apache.log4j.Logger;
/*    */ 
/*    */ public class CaptchaUtils
/*    */ {
/* 13 */   private static Logger logger = Logger.getLogger(CaptchaUtils.class);
/*    */ 
/*    */   public static final boolean checkCaptcha(HttpServletRequest request, String value)
/*    */   {
/* 23 */     boolean result = false;
/* 24 */     HttpSession session = request.getSession();
/* 25 */     Captcha captcha = (Captcha)session.getAttribute("captcha");
/* 26 */     if ((captcha != null) && (captcha instanceof Captcha)) {
/* 27 */       result = captcha.check(value);
/*    */     }
/* 29 */     if (captcha != null) {
/* 30 */       session.removeAttribute("captcha");
/*    */     }
/* 32 */     return result;
/*    */   }
/*    */ 
/*    */   public static final void createCaptcha(HttpServletRequest request, HttpServletResponse response)
/*    */   {
/*    */     try
/*    */     {
/* 44 */       response.setContentType("image/png");
/* 45 */       response.setHeader("Cache-Control", "no-cache");
/* 46 */       OutputStream out = response.getOutputStream();
/* 47 */       Captcha captcha = CaptchaFactory.getCaptcha();
/* 48 */       logger.info(captcha);
/* 49 */       HttpSession session = request.getSession();
/* 50 */       session.setAttribute("captcha", captcha);
/* 51 */       out.write(captcha.getImage());
/* 52 */       out.close();
/*    */     } catch (Exception e) {
/* 54 */       logger.error("生成验证码失败！" + e.getMessage());
/*    */     }
/*    */   }
/*    */ }

/* Location:           C:\Users\Administrator\Desktop\新建文件夹\WEB-INF\classes\
 * Qualified Name:     com.qmsk.business.captcha.CaptchaUtils
 * JD-Core Version:    0.5.3
 */